<script setup lang="ts">
	import { onMounted, ref } from "vue";
	import { http } from "@/utils/http"
	import Banner from "../index/components/Banner.vue"
	import type { BannerItem, CategoryItem, HotItem } from "@/types/home";
	import { getHomeBannerAPI, getCategoryApi, hotApi } from "@/services/home";

	import { onLoad } from "@dcloudio/uni-app";
	const BannerList = ref<BannerItem[]>([]);
	const yijilist=ref([]);
	const getbanner = async () => {
		const res = await http({
			url: "/home/banner?distributionSite=2",
			method: "GET",
		})
		console.log(res)
		BannerList.value = res.result;
	}
	const getyjfl=async()=>{
		const res=await http({
			url:"/category/top",
			method:"GET"
		})
		console.log(res)
		yijilist.value=res.result
		listsp.value=yijilist.value[activeindex.value].children;
	
	}
	const listsp=ref([]);
	const activeindex=ref(0);
	const dj=(index)=>{
		activeindex.value=index
		listsp.value=yijilist.value[activeindex.value].children;
		console.log(listsp.value)
	}
	onMounted(() => {
		getbanner()
getyjfl()
	})

	//
</script>

<template>
	<view class="viewport">
		<view class="search">
			<view class="input">
				<text class="icon-search">女靴</text>
			</view>
		</view>
		<view class="categories">
			<scroll-view scroll-y="true" class="primary">
				<view v-for="(item,index) in yijilist" :key="item.id" @click="dj(index)" class="item" :class="{active:index === activeindex}">
					<text class="name">{{item.name}}</text>
				</view>
			</scroll-view>
			<scroll-view class="secondary" scroll-y>
				<Banner :list="BannerList"></Banner>
				<view class="panel" v-for="item1 in listsp" :key="item1">
					<view class="title">
						<text class="name">{{item1.name}}</text>
						<navigator class="more" hover-class="none">全部</navigator>

					</view>
					<view class="section">
						<navigator v-for="item2 in item1.goods" class="goods" hover-class="none" :url="`/pages/goods/goods?id=${item2.id}`">
							<image class="image"
								:src="item2.picture"></image>
							<view class="name ellipsis">
								{{item2.name}}

							</view>
							<view class="price">
								<text class="symbol">￥</text>
								<text class="number">{{item2.price}}</text>
							</view>
						</navigator>

					</view>

				</view>
			</scroll-view>
		</view>

	</view>
</template>

<style lang="scss">
	//
	page {
		height: 100%;
		overflow: hidden;
	}

	.viewport {
		height: 100%;
		display: flex;
		flex-direction: column;
	}

	.search {
		padding: 0 30rpx 20rpx;
		background-color: #fff;

		.input {
			display: flex;
			align-items: center;
			justify-content: space-between;
			height: 64rpx;
			padding-left: 26rpx;
			color: #8b8b8b;
			font-size: 28rpx;
			border-radius: 32rpx;
			background: #f3f4f4;
		}
	}

	.icon-search {
		&:before {
			margin-right: 10rpx;
		}
	}

	.categories {
		display: flex;
		flex: 1;
		min-height: 400rpx;
	}

	.primary {
		overflow: hidden;
		width: 180rpx;
		flex: none;
		background: #f6f6f6;

		.item {
			display: flex;
			justify-content: center;
			align-items: center;
			height: 96rpx;
			font-size: 26rpx;
			color: #595c63;
			position: relative;

			&::after {
				content: '';
				position: absolute;
				left: 42rpx;
				bottom: 0;
				width: 96rpx;
				border-top: 1rpx solid #e3e4e7;
			}
		}

		.active {
			background: #fff;

			&::before {
				content: '';
				position: absolute;
				left: 0;
				top: 0;
				width: 8rpx;
				height: 100%;
				background: #27ba9b;
			}
		}
	}

	.primary .item:last-child::after,
	.primary .active::after {
		display: none;
	}

	.secondary {
		background-color: #fff;

		.carousel {
			height: 200rpx;
			margin: 0 30rpx 20rpx;
			border-radius: 4rpx;
			overflow: hidden;
		}

		.panel {
			margin: 0 30rpx 0rpx;
		}

		.title {
			height: 60rpx;
			line-height: 60rpx;
			color: #333;
			font-size: 28rpx;
			border-bottom: 1rpx solid #f7f7f8;

			.more {
				float: right;
				padding-left: 20rpx;
				font-size: 24rpx;
				color: #999;
			}
		}

		.more {
			&::after {
				font-family: 'erabbit' !important;
				content: '\e6c2';
			}
		}

		.section {
			width: 100%;
			display: flex;
			flex-wrap: wrap;
			padding: 20rpx 0;

			.goods {
				width: 150rpx;
				margin: 0rpx 30rpx 20rpx 0;

				&:nth-child(3n) {
					margin-right: 0;
				}

				image {
					width: 150rpx;
					height: 150rpx;
				}

				.name {
					padding: 5rpx;
					font-size: 22rpx;
					color: #333;
				}

				.price {
					padding: 5rpx;
					font-size: 18rpx;
					color: #cf4444;
				}

				.number {
					font-size: 24rpx;
					margin-left: 2rpx;
				}
			}
		}
	}
</style>